pragma License (GPL);
--
-- drk-utils-fast_exp.adb
--
-- Copyright (C) 2012 - Thibault BUREL
--
-- This file is part of DRK.BigRat.
--
-- DRK.BigRat is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- DRK.BigRat is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with DRK.BigRat.  If not, see <http://www.gnu.org/licenses/>
--

package body DRK.Utils.Fast_Exp is

   function Exp (N : in Element; E : in Exposant) return Element
   is
      Tmp : Element;
   begin

      if E = 1 then

         return N;

      elsif E mod 2 = 0 then

         Tmp := Exp (N, E / 2);

         return Tmp * Tmp;

      else

         Tmp := Exp (N, E - 1);

         return N * Tmp;

      end if;

   end Exp;

end DRK.Utils.Fast_Exp;
